﻿using System.Collections.Generic;
using System.Linq;
using EPiServer.Common.Tags;
using EPiServer.Community.Blog;
using JoelAbrahamsson.MetaWeblog;

namespace JoelAbrahamsson.BlogExtensions
{
    public class BlogTagProvider : IBlogTagProvider
    {
        public IEnumerable<ITag> GetTags(Blog blog)
        {
            EntryCollection allEntriesInBlog = blog.GetEntries(1, int.MaxValue - 1);
            
            List<ITag> tags = new List<ITag>();
            foreach (Entry entry in allEntriesInBlog)
            {
                foreach (ITag tag in entry.Tags)
                {
                    if(tags.Count(addedTag => addedTag.ID == tag.ID) == 0)
                        tags.Add(tag);
                }
            }

            return tags;
        }
    }
}
